<template>
  <div class="loginMain">
    <el-row class="login">
      <el-col :span="8" :offset="8">
        <el-card class="loginForm">
          <div slot="header" class="clearfix">
            <span>用户登录</span>
          </div>
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户名" prop="userName">
              <el-input v-model="ruleForm.userName"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input v-model="ruleForm.password" show-password></el-input>
            </el-form-item>
            <el-form-item label="验证码" prop="validateCode">
              <el-col :span="12">
                <el-input v-model="ruleForm.validateCode"></el-input>
              </el-col>
              <el-col :span="8" :offset="2">
                <img
                  src="" />
              </el-col>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
              <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>

  </div>
</template>

<script>
  import { Login } from '../api/admin';
  import Cookie from 'js-cookie';
  import Vue from 'vue';
  export default {
    name: 'RbacProjectUiLogin',

    data() {
      return {
        ruleForm: {
          userName: '',
          password: '',
          validateCode: 'aaaa'
        },
        rules: {
          userName: [
            { required: true, message: '请输入用户名', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        }
      };
    },

    mounted() {
      
    },

    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            Login(this.ruleForm).then(m => {
              if (m.info < 2) {
                this.$message({
                  message: m.message,
                  type: 'warning'
                });
              } else {
                Cookie.set("token",JSON.stringify(m));
                Vue.ls.set("jwt",m);
                this.$router.push("/");
              }
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
  };
</script>
<style>
  .loginMain {
    height: 100%;
    background: url("../assets/loginbg.png");
    background-size: 100% auto;
    background-repeat: no-repeat;
  }

  .loginForm {
    margin: 0 auto;
    margin-top: 13em;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both
  }
</style>